package com.ming.attendance.mapper;

import com.ming.attendance.po.Beacon;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface BeaconMapper {

    // 通过beacon_uuid查找Beacon
    @Select("SELECT `beaconId`,`uuid`,`accuracy`,`major`,`minor`,`proximity`,`rssi`,`using` " +
            "FROM beacon " +
            "WHERE beaconId = #{beaconId}")
    Beacon getBeaconById(String beaconId);

    // 通过uuid、major、minor找到beacon
    Beacon getBeaconByThree(Beacon beacon);

    @Insert("INSERT INTO \n" +
            "`beacon`(`beaconId`,`uuid`,`accuracy`,`major`,`minor`,`proximity`,`rssi`,`using`)\n" +
            "VALUES (#{beaconId},#{uuid},#{accuracy},#{major},#{minor},#{proximity},#{rssi},#{using})")
    Integer addBeacon(Beacon beacon);

    // 解绑Beacon
    @Update("UPDATE `beacon` SET `using`=#{using} WHERE `beaconId` = #{beaconId}")
    int updateBeacon(Beacon beacon);
}
